<template>
  <div>
    <!-- 检索课程分类，安装课程分类模糊检索 -->
    <el-input v-model="filterText" placeholder="Filter keyword" style="margin-bottom:30px;" />

    <el-tree
      ref="tree2"
      :data="data2"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />
  </div>
</template>

<script>
import SubjectApi from "@/api/edu/subject";
export default {
  components: {},
  props: {},
  data() {
    return {
      filterText: "",
      data2: [],
      defaultProps: {
        children: "children",
        label: "title"
      }
    };
  },
  watch: {
    //监听变量的变化，用于检索课程分类
    filterText(val) {
      this.$refs.tree2.filter(val);
    }
  },
  computed: {},
  methods: {
    filterNode(value, data) {
      if (!value) return true;
      //将检索词和分类名都转成小写，像验证码不区分大小写也是这样处理的
      return data.title.toLowerCase().indexOf(value.toLowerCase()) !== -1;
    },
    getSubjectList() {
      SubjectApi.getSubjectList().then(res => {
        this.data2 = res.data.list;
      });
    }
  },
  created() {
    this.getSubjectList();
  },
  mounted() {}
};
</script>
<style scoped>
</style>